#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
using namespace std;
typedef long long ll;
const __int128 INF = 1e27;

__int128 a[110];

__int128 sum[110][110];

inline __int128 read(){
    __int128 x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9'){
        if(ch == '-')
            f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9'){
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
inline void print(__int128 x){
    if(x < 0){
        putchar('-');
        x = -x;
    }
    if(x > 9)
        print(x / 10);
    putchar(x % 10 + '0');
}

//__int128 min(__int128 a, __int128 b) {
//    return (a < b) ? a : b;
//}

int main()
{
    int n;
    cin>>n;
    
    for(int i=1;i<=n;i++) a[i]=read();
    
    for(int len=3;len<=n;len++)
    {
        for(int l=1; l+len-1<=n; l++)
        {
            int r=l+len-1;
            
            sum[l][r]=INF;
            
            for(int k=l+1; k<r; k++)
            {
                sum[l][r]=min(sum[l][r],sum[l][k]+sum[k][r]+a[l]*a[k]*a[r]);
            }
        }
    }
    
    __int128 ans=sum[1][1+n-1];

    print(ans);
}

